using System.Collections.Generic;
using UnityEngine;

public class ReputationDev : MonoBehaviour
{
	public UILabel nameLabel;

	public UILabel statusLabel;

	public UILabel repLabel;

	public UILabel moneyLabel;

	public UISlider repSlider;

	public UIButton saveBuuton;

	private Dictionary<string, ReputationMapInfo> info;

	private List<string> keys = new List<string>();

	private int keyIndex;

	private ReputationMapInfo current;

	private float newRep;

	private void Awake()
	{
		info = ReputationManager.Instance.GetInfo();
		foreach (KeyValuePair<string, ReputationMapInfo> item in info)
		{
			keys.Add(item.Key);
		}
	}

	private void Start()
	{
		Refresh();
	}

	private void Refresh()
	{
		current = info[keys[keyIndex]];
		nameLabel.text = current.name;
		if (current.state == DistrictState.Captured)
		{
			statusLabel.text = "Захвачен";
		}
		else if (current.state == DistrictState.Locked)
		{
			statusLabel.text = "Заблокирован";
		}
		else
		{
			statusLabel.text = "Разблокирован";
		}
		repLabel.text = current.curReputation + "/" + current.maxReputation;
		moneyLabel.text = current.name;
		repSlider.value = current.curReputation / current.maxReputation;
		repLabel.color = Color.white;
		saveBuuton.isEnabled = false;
	}

	public void ShowNext()
	{
		keyIndex++;
		if (keyIndex > keys.Count - 1)
		{
			keyIndex = 0;
		}
		Refresh();
	}

	public void ShowPrev()
	{
		keyIndex--;
		if (keyIndex < 0)
		{
			keyIndex = keys.Count - 1;
		}
		Refresh();
	}

	public void Save()
	{
		ReputationManager.Instance.DebugSetReputation(newRep, current.name);
		info = ReputationManager.Instance.GetInfo();
		Refresh();
	}

	public void ChangeRep()
	{
		if ((double)Mathf.Abs(repSlider.value - newRep / current.maxReputation) > 0.001)
		{
			saveBuuton.isEnabled = true;
			newRep = repSlider.value * current.maxReputation;
			newRep = (float)(int)(newRep * 10f) / 10f;
			repLabel.text = newRep + "/" + current.maxReputation;
			repLabel.color = Color.green;
		}
	}
}
